<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>高德地图-通过经纬度解析地址信息</title>
  <script>
    // 设置密钥
    window._AMapSecurityConfig = {
      securityJsCode: "7973b6d0c2aeedda7dc4e47baaccbbf3",
    }
  </script>
  <!-- 引入高德地图  -->
  <script src="https://webapi.amap.com/maps?v=2.0&key=8e4cb94aea50258059cda18f09913061&plugin=AMap.Geocoder"></script>
</head>
<body>
<script>
  window.onload = function () {
    /**
     * 获取url所有参数
     */
    function getUrlParams() {
      const url = window.location.search;
      const query = {};
      if (url.indexOf("?") !== -1) {
        const str = url.substr(1).split("&");
        for (let i = 0; i < str.length; i++) {
          query[str[i].split("=")[0]] = decodeURIComponent(str[i].split("=")[1]);
        }
      }
      return query;
    }

    // 获取所有参数
    const query = getUrlParams();
    const longitude = query.longitude;
    const latitude = query.latitude;

    /**
     * 获取-H5经纬度解析城市信息
     */
    function getH5CityInfoFn() {
      let geocoder = null;
      // 初始化‌地理编码
      AMap.plugin("AMap.Geocoder", () => {
        geocoder = new AMap.Geocoder({
          radius: 1000,
          extensions: "all"
        });
      });
      // 根据经纬度进行逆地理编码查询
      geocoder.getAddress([longitude, latitude], (status, res) => {
        if (status === "complete" && res.info === "OK") {
          if (res.regeocode && res.regeocode.formattedAddress) {
            // 获取城市
            const areaName = res.regeocode.addressComponent.district;
            // 跳转回调
            window.location.href = "myapp://getCityInfo?areaName=" + areaName
          } else {
            // 跳转回调
            window.location.href = "myapp://getCityInfo?areaName="
          }
        } else {
          // 跳转回调
          window.location.href = "myapp://getCityInfo?areaName="
        }
      });
    }

    /**
     * 获取-H5经纬度解析城市信息
     */
    getH5CityInfoFn();
  }
</script>
</body>
</html>